package com.ocom.xfrecode.service.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ocom.common.entity.payconfig.EntityMqttOperation;
import com.ocom.xfrecode.mapper.XfMqttOperationMapper;
import com.ocom.xfrecode.service.XfMqttOperationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service
public class XfMqttOperationServiceImpl  extends ServiceImpl<XfMqttOperationMapper, EntityMqttOperation> implements XfMqttOperationService {

    @Override
    public boolean saveOrUpdate(EntityMqttOperation entity) {
        EntityMqttOperation entityMqttOperation = this.getOne(Wrappers.lambdaQuery(EntityMqttOperation.class).eq(EntityMqttOperation::getOrderNo,entity.getOrderNo()).eq(EntityMqttOperation::getOrderId,entity.getOrderId()).eq(EntityMqttOperation::getMonthValue,entity.getMonthValue()).last("limit 1"));
        boolean result;
        if(ObjectUtil.isEmpty(entityMqttOperation)){
            result = this.save(entity);
        }else{
            result = this.update(entity,Wrappers.lambdaQuery(EntityMqttOperation.class).eq(EntityMqttOperation::getId,entityMqttOperation.getId()).eq(EntityMqttOperation::getMonthValue,entity.getMonthValue()));
        }
        return result;
    }
}
